from django import forms

class Bootstrap(): # 定义一个公共的类，让下面的类继承，减少代码量
    # 定义一个排除添加样式列表
    exclude_list = []
    # 循环找到所有的字段，添加class:form-control,生成对应的bootstrap样式输入框
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        for name, field in self.fields.items():
            if name not in self.exclude_list:
                 # print(name, field)
               field.widget.attrs = {'class': 'form-control', "placeholder": field.label}

class BootstrapModelForm(Bootstrap,forms.ModelForm):
             pass

class BootstrapForm(Bootstrap,forms.Form):
             pass
